package middleware

import (
	"github.com/gin-gonic/gin"
	"github.com/go-kratos/kratos/v2/log"
)

func NewRecoverLog(logger *log.Helper) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		defer func() {
			if err := recover(); err != nil {
				logger.WithContext(ctx).Errorf("%+v", err)
				ctx.AbortWithStatusJSON(500, gin.H{
					"message": "Internal Server Error",
				})
			}
		}()
		ctx.Next()

	}
}
